package cn.dust.design.pattern.behavioral.iterator;

/**
 * @Author: dust
 * @Date: 2019/11/27 18:53
 */
public class Test {

    public static void main(String[] args) {
        Course course=new Course("d0");
        Course course1=new Course("d1");
        Course course2=new Course("d2");
        Course course3=new Course("d3");
        Course course4=new Course("d4");
        Course course5=new Course("d5");

        CourseAggregate courseAggregate=new CourseAggregateImpl();

        courseAggregate.addCourse(course);
        courseAggregate.addCourse(course1);
        courseAggregate.addCourse(course2);
        courseAggregate.addCourse(course3);
        courseAggregate.addCourse(course4);
        courseAggregate.addCourse(course5);
        System.out.println("课程列表");

        printCourses(courseAggregate);

        courseAggregate.removeCourse(course4);
        courseAggregate.removeCourse(course5);
        System.out.println("操作之后的课程列表");
        printCourses(courseAggregate);




    }

    public static void printCourses(CourseAggregate courseAggregates){
        CourseIterator courseIterator=courseAggregates.getCourseIterator();
        while(!courseIterator.isLastCourse()){
            Course course=courseIterator.nextCourse();
            System.out.println(course.getName());
        }
    }

}
